from app.exts import db
from sqlalchemy.ext.hybrid import hybrid_property
class TopicModel(db.Model):
    __tablename__='topic'
    id=db.Column(db.Integer,primary_key=True,autoincrement=True)
    name=db.Column(db.String(100),nullable=False)
    desc=db.Column(db.Text)
    cover=db.Column(db.String(200))
    blogstop = db.relationship("BlogModel", back_populates="topic")

    @hybrid_property
    def blog_count(self):
        blogs=self.blogstop
        blogs=[b for b in blogs if b.status == 'published' and b.is_deleted == False]
        return len(blogs) # 内存计数